import numpy as np

from .module import Module
from autograd import Tensor
from autograd.nn.parameter import Parameter
from .. import functional as F


class Linear(Module):
    r"""A simple linear layer
    
    """

    def __init__(self, in_features: int, out_features: int, bias: bool = True) -> None:
        super(Linear, self).__init__()
        self.in_features = in_features
        self.out_features = out_features
        self.weight = Parameter(Tensor.uniform(size=[out_features, in_features]))
        if bias:
            self.bias = Parameter(Tensor.uniform(size=out_features))
        else:
            #self.register_parameter('bias', None)
            self.bias = None

    def forward(self, x):
        return F.linear(x, self.weight, self.bias)


    def extra_repr(self) -> str:
        return 'in_features={}, out_features={}, bias={}'.format(
            self.in_features, self.out_features, self.bias is not None
        )
